package apresentacao.caminhoneiro;

import tcc.caminhoneiro.R;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;

import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.ArrayAdapter;


public class Fragment_Menu_Buscas extends Fragment{
	
	String [] menu = {"Busca Cidade-Cidade", "Busca Estado-Estado", "Busca por Raio"};

	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		
		View view = inflater.inflate(R.layout.fragment_menu_buscas, null);
		inicializar(view);
		return view;
	}
	
	private void inicializar(View view){
		ListView ajustesListView 				= (ListView) view.findViewById(R.id.menuListView);
		//ajustesListView.setAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, menu));
		ajustesListView.setAdapter(new ArrayAdapter<String>(getActivity(), R.layout.item_linha, menu));
		OnItemClickListener eventoClick = new OnItemClickListener(){

			@Override
			public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
				switch(position){
				  case 0:{
					  Fragment_Buscar_Fretes fragment = new Fragment_Buscar_Fretes();
					  getActivity().getSupportFragmentManager().beginTransaction().addToBackStack("MenuBuscasCC").replace(R.id.menu_principal_llFragment, fragment).commit();	
					  break;
				  } 
				  case 1:{
					  Fragment_Buscar_Fretes_Estado fragment = new Fragment_Buscar_Fretes_Estado();
					  getActivity().getSupportFragmentManager().beginTransaction().addToBackStack("MenuBuscasEE").replace(R.id.menu_principal_llFragment, fragment).commit();	
					  break;
				  }
				  case 2:{
					  Fragment_Buscar_Fretes_Raio fragment = new Fragment_Buscar_Fretes_Raio();
					  getActivity().getSupportFragmentManager().beginTransaction().addToBackStack("MenuBuscasRaio").replace(R.id.menu_principal_llFragment, fragment).commit();	
					  break;
				  }
				}
			}
			
		};
		ajustesListView.setOnItemClickListener(eventoClick);
		
	}
}
